package com.hxl.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class RestFulController {
    //原来的方式：localhost:8080/add?a=1&b=2
    @RequestMapping("/add")
    public String test(int a, int b, Model model){
        int res = a + b;
        model.addAttribute("msg","结果为" + res);
        return "test";
    }

    //RestFul：localhost:8080/add2/1/2
    @RequestMapping("/add2/{a}/{b}")
    public String test1(@PathVariable int a,@PathVariable int b, Model model){
        int res = a + b;
        model.addAttribute("msg","结果为" + res);
        return "test";
    }
    @RequestMapping(value = "/add/{a}/{b}",method = {RequestMethod.GET})
    public String test2(@PathVariable int a,@PathVariable int b, Model model){
        int res = a + b;
        model.addAttribute("msg","结果为" + res);
        return "test";
    }
    @RequestMapping(value = "/add/{a}/{b}",method = {RequestMethod.POST})
    public String test3(@PathVariable int a,@PathVariable int b, Model model){
        int res = a + b;
        model.addAttribute("msg","结果为" + res);
        return "test";
    }
}
